<template>
  <div class="posttable">
    <el-row>
      <el-col :span="24" style="padding-right: 30px;padding-left: 40px;">
        <div class="addform">
          <el-form
            v-if="form"
            :label-position="labelPosition"
            ref="form"
            :model="form"
            :rules="rules"
          >
            <el-row>
              <el-col :span="5">
                <el-form-item label="需求名称" prop="name">
                  <el-input
                    v-model="form.name"
                    :disabled="input['需求名称']"
                    placeholder="请输入需求名称"
                    style="width:274px;"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="5" :offset="1">
                <el-form-item label="客户简称" prop="customerName">
                  <el-select
                    v-model="form.customerName"
                    @change="customerNameChange"
                    :disabled="input['客户简称']"
                    placeholder="请选择客户"
                  >
                    <el-option
                      v-for="item in customerNa"
                      :key="item.id"
                      :label="item.name"
                      :value="item.name"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="5" :offset="1">
                <el-form-item label="职位名称" prop="postName" class="dutyM">
                  <el-select
                    v-model="form.postName"
                    :disabled="input['职位名称']"
                    @change="postNameChange"
                    placeholder="请选择职位名称"
                    style="width:274px;"
                  >
                    <el-option v-for="item in postNameList" :key="item" :label="item" :value="item"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="5" :offset="1">
                <el-form-item label="职位级别" prop="postLevel" class="dutyM">
                  <el-select
                    placeholder="请输入职位级别"
                    multiple
                    v-model.trim="form.postLevel"
                    style="width: 274px"
                    :disabled="input['职位级别']"
                  >
                    <el-option
                      v-for="item in postLevelList"
                      :key="item"
                      :label="item"
                      :value="item"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="5">
                <el-form-item label="需求状态" prop="status">
                  <el-select
                    v-if="status"
                    v-model="form.status"
                    :disabled="input['需求状态']"
                    placeholder="正常/暂停/关闭"
                  >
                    <el-option label="正常" value="正常"></el-option>
                    <el-option label="暂停" value="暂停"></el-option>
                    <el-option label="关闭" value="关闭"></el-option>
                  </el-select>
                  <el-select
                    v-if="!status"
                    v-model="form.status"
                    :disabled="input['需求状态']"
                    placeholder="预设"
                  >
                    <el-option label="预设" value="预设"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="5" :offset="1">
                <el-form-item label="发布人(选填)" prop="introducer">
                  <el-input
                    v-model="form.introducer"
                    :disabled="input['发布人(选填)']"
                    placeholder="请输入发布人"
                    style="width:274px;"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="5" :offset="1">
                <el-form-item label="所属区域" prop="area">
                  <el-select
                    v-model="form.area"
                    multiple
                    :disabled="input['所属区域']"
                    placeholder="请选择区域"
                  >
                    <el-option v-for="item in Areas" :key="item.index" :label="item" :value="item"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="5" :offset="1">
                <el-form-item label="职位类型" prop="postType" class="dutyM">
                  <el-select
                    v-model="form.postType"
                    :disabled="input['职位类型']"
                    placeholder="开发、测试、网络、运维、其他"
                  >
                    <el-option label="开发" value="开发"></el-option>
                    <el-option label="测试" value="测试"></el-option>
                    <el-option label="网络" value="网络"></el-option>
                    <el-option label="运维" value="运维"></el-option>
                    <el-option label="其他" value="其他"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="5">
                <el-form-item label="需求程度" class="star dutyM" prop="nextStar">
                  <el-select v-model="form.nextStar" :disabled="input['需求程度']" class="starNum">
                    <el-option
                      v-for="item in star"
                      :key="item.num"
                      :label="item.label"
                      :value="item.num"
                    >
                      <el-button
                        size="mini"
                        v-if="item.num == 3"
                        style="background-color: #FF1C1D;color: #fff;"
                      >困难
                      </el-button>
                      <el-button
                        size="mini"
                        v-if="item.num == 2"
                        style="background-color: #2931FE;color: #fff;"
                      >普通
                      </el-button>
                      <el-button
                        size="mini"
                        v-if="item.num == 1"
                        style="background-color: #FFC027;color: #fff;"
                      >简单
                      </el-button>
                      <el-button
                        size="mini"
                        v-if="item.num == 0"
                        style="background-color: #04344a;color: #fff;"
                      >空
                      </el-button>
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              
              <el-col :span="5" :offset="1">
                <el-form-item label="需求人数" prop="number" class="dutyM">
                  <el-input
                    :disabled="input['需求人数']"
                    placeholder="请输入需求人数"
                    v-model.trim="form.number"
                    style="width: 274px"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="5" :offset="1">
                <el-form-item label="薪资上限" prop="salaryCap">
                  <el-input
                    placeholder="请输入薪资上限"
                    :disabled="input['薪资上限']"
                    v-model.trim="form.salaryCap"
                    style="width: 274px"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="5" :offset="1">
                <el-form-item label="薪数" prop="salaryNum">
                  <el-input
                    placeholder="请输入薪数"
                    :disabled="input['薪数']"
                    v-model.trim="form.salaryNum"
                    style="width: 274px"
                  ></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="5">
                <el-form-item label="工作地点" prop="addr">
                  <el-input
                    placeholder="请输入工作地点"
                    :disabled="input['工作地点']"
                    v-model.trim="form.addr"
                    style="width: 274px"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="5" :offset="1">
                <el-form-item label="作息时间" prop="timeTable">
                  <el-input
                    placeholder="请输入作息时间"
                    :disabled="input['作息时间']"
                    v-model.trim="form.timeTable"
                    style="width: 274px"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="5" :offset="1">
                <el-form-item label="发布时间" prop="putTime">
                  <el-date-picker
                    type="date"
                    :disabled="input['发布时间']"
                    v-model="form.putTime"
                    value-format="yyyy-MM-dd"
                    format="yyyy-MM-dd"
                    style="width: 274px;"
                  ></el-date-picker>
                  <div class="el-form-item__error" v-if="error">选择时间错误</div>
                </el-form-item>
              </el-col>
              <el-col :span="5" :offset="1">
                <el-form-item label="截止时间" prop="endTime">
                  <el-date-picker
                    type="date"
                    :disabled="input['截止时间']"
                    v-model="form.endTime"
                    value-format="yyyy-MM-dd"
                    format="yyyy-MM-dd"
                    style="width: 274px;"
                  ></el-date-picker>
                  <div class="el-form-item__error" v-if="error1">选择时间错误</div>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="5" :offset="0">
                <el-form-item label="期望到岗时间" prop="expectTime">
                  <el-input
                    :disabled="input['期望到岗时间']"
                    v-model.trim="form.expectTime"
                    style="width: 274px"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="5" :offset="1">
                <el-form-item label="技术面试" prop="techInterview">
                  <el-select
                    v-model="form.techInterview"
                    :disabled="input['技术面试']"
                    placeholder="需要/不需要"
                  >
                    <el-option label="需要" value="需要"></el-option>
                    <el-option label="不需要" value="不需要"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="5" :offset="1" class="process">
                <el-form-item label="面试流程" prop="interviewProcess">
                  <el-select
                    placeholder="请选择面试流程"
                    :disabled="input['面试流程']"
                    v-model.trim="form.interviewProcess"
                  >
                    <el-option
                      v-for="item in processList"
                      :key="item.sysInterviewProcessId"
                      :label="item.interviewProcess"
                      :value="item.interviewProcess"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="5" :offset="1">
                <el-form-item label="工作年限" prop="workSeniority">
                  <el-select
                    v-model="form.workSeniority"
                    :disabled="input['工作年限']"
                    placeholder="请选择工作年限"
                  >
                    <el-option
                      v-for="(item,index) in year"
                      :key="index"
                      :label="item"
                      :value="item"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="5">
                <el-form-item label="合同签订日期" prop="contractSigningDate">
                  <el-input
                    placeholder="请输入合同签订日期"
                    v-model.trim="form.contractSigningDate"
                    style="width: 274px"
                    disabled
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="5" :offset="1">
                <el-form-item label="项目时长" prop="projectDuration">
                  <el-input
                    placeholder="请输入项目时长"
                    v-model.trim="form.projectDuration"
                    style="width: 274px"
                    disabled
                  ></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row v-if="jiaofuren">
              <el-col :span="5" v-if="keyBool">
                <!-- 招聘助理能看到的关键词 -->
                <el-form-item label="关键词" prop="ordinaryKeywords">
                  <el-select
                    v-model.trim="form.ordinaryKeywords"
                    multiple
                    filterable
                    allow-create
                    default-first-option
                    :disabled="input['关键词']"
                    placeholder="请输入关键词"
                    style="width: 274px"
                  ></el-select>
                </el-form-item>
              </el-col>
              <el-col :span="5" :offset="offff" class="hr">
                <el-form-item label="组别" class="mainPeople" prop="nextHr">
                  <el-select
                    v-model="form.nextHr"
                    multiple
                    :disabled="input['组别']"
                    placeholder="请选择组别"
                  >
                    <el-option v-for="item in mainHr" :key="item.id" :label="item" :value="item"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="5" :offset="1" v-if="isAdmin">
                <!-- admin能看到修改的关键词 -->
                <el-form-item label="补充关键词" prop="mainKeywords">
                  <el-select
                    disabled
                    v-model.trim="form.mainKeywords"
                    multiple
                    filterable
                    allow-create
                    default-first-option
                    placeholder="请输入补充关键词"
                    style="width: 274px"
                  ></el-select>
                </el-form-item>
              </el-col>
              <el-col v-if="isGangjiaosuo" :span="5" :offset="offs">
                <el-form-item label="需求编号" prop="no" class="dutyM">
                  <el-input placeholder="请输入需求编号" v-model.trim="form.no" style="width: 274px"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="5">
                <el-form-item label="面试地点" class="dutyM">
                  <el-input
                    placeholder="请输入面试地点"
                    :disabled="editBool"
                    v-model.trim="form.interviewPlace"
                    style="width: 274px"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="5" :offset="1">
                <el-form-item label="面试联系人" class="dutyM">
                  <el-input
                    placeholder="请输入面试联系人"
                    :disabled="editBool"
                    v-model.trim="form.interviewContacts"
                    style="width: 274px"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="5" :offset="1">
                <el-form-item label="联系方式" prop="contactInfo" :rules="PhoneRules" class="dutyM">
                  <el-input
                    placeholder="请输入联系方式"
                    :disabled="editBool"
                    v-model.trim="form.contactInfo"
                    style="width: 274px"
                  ></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="5">
                <el-form-item label="技术电面" prop="isDm">
                  <el-select v-model="form.isDm" placeholder="请选择是否需要技术电面" @change="isDmclear()" :disabled="editDm">
                    <el-option label="需要" value="Y"></el-option>
                    <el-option label="不需要" value="N"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="5" :offset="1" v-if="form.isDm == 'Y'">
                <el-form-item label="电面方向" prop="direction">
                  <el-select v-model="form.direction" placeholder="请选择电面方向" :disabled="editDm"
                             @change="directionChange">
                    <el-option v-for="item in directions" :key="item" :label="item" :value="item"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="5" :offset="1" v-if="form.isDm == 'Y'">
                <el-form-item label="电面人员" prop="charge">
                  <el-select v-model="form.charge" placeholder="请选择电面人员" :disabled="editDm">
                    <el-option v-for="item in charges" :key="item" :label="item" :value="item"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row v-if="jiaofuren">
              <el-col v-for="(item,index) in form.liaisonList" :key="index">
                <el-col :span="5">
                  <el-form-item :prop="'liaisonList.'+index+'.receiverMail'" :rules="EmailRules">
                    <el-col>
                      <span style="color:#333;">
                        <span style="color:#F56C6C;">*</span> 收件人邮箱
                      </span>
                    </el-col>
                    <el-input
                      v-if="!isUnifiedInter"
                      placeholder="请输入收件人邮箱"
                      v-model.trim="item.receiverMail"
                      style="width: 274px"
                      disabled
                    ></el-input>
                    <el-select
                      v-if="isUnifiedInter"
                      placeholder="请选择收件人邮箱"
                      v-model.trim="item.receiverMail"
                      style="width: 274px"
                      @change="recMailChange"
                      disabled
                    >
                      <el-option
                        v-for="item2 in recMails"
                        :key="item2.id"
                        :label="item2.mail"
                        :value="item2.mail"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col
                  :span="5"
                  v-for="(item1,index1) in item.cpSendMails"
                  :key="index1"
                  :class="{'el-col-offset-1' : (index1 !== 3)}"
                >
                  <el-form-item
                    v-if="item.cpSendMails.length == 1"
                    :prop="'liaisonList.'+index+'.cpSendMails.'+index1+'.mail'"
                    :rules="EmailRules3"
                  >
                    <el-col>
                      <span style="color:#333;">
                        <span v-if="item.cpSendMails.length !== 1" style="color:#F56C6C;">*</span> 抄送人邮箱
                      </span>
                      <i
                        class="el-icon-circle-plus"
                        style="color:#1198ff;font-size: 12px;"
                        v-if="index1 == 0"
                        @click="addcopymail(index)"
                      ></i>
                      <span
                        v-if="index1 == 0"
                        style="color:#1198ff;font-size: 14px;"
                        @click="addcopymail(index)"
                      >添加</span>
                      
                      <i
                        class="el-icon-circle-close"
                        style="color:#f41f1e;font-size: 12px;"
                        v-if="index1 !== 0"
                        @click="deletecopymail(index,index1)"
                      ></i>
                      <span
                        style="color:#f41f1e;font-size: 14px;"
                        v-if="index1 !== 0"
                        @click="deletecopymail(index,index1)"
                      >删除</span>
                    </el-col>
                    <el-input placeholder="请输入抄送人邮箱" v-model.trim="item1.mail" style="width: 274px" disabled></el-input>
                  </el-form-item>
                  <el-form-item
                    v-if="item.cpSendMails.length > 1"
                    :prop="'liaisonList.'+index+'.cpSendMails.'+index1+'.mail'"
                    :rules="EmailRules1"
                  >
                    <el-col>
                      <span style="color:#333;">
                        <span v-if="item.cpSendMails.length !== 1" style="color:#F56C6C;">*</span> 抄送人邮箱
                      </span>
                      <i
                        class="el-icon-circle-plus"
                        style="color:#1198ff;font-size: 12px;cursor: pointer;"
                        v-if="index1 == 0"
                        @click="addcopymail(index)"
                      ></i>
                      <span
                        v-if="index1 == 0"
                        style="color:#1198ff;font-size: 14px;cursor: pointer;"
                        @click="addcopymail(index)"
                      >添加</span>
                      
                      <i
                        class="el-icon-circle-close"
                        style="color:#f41f1e;font-size: 12px;cursor: pointer;"
                        v-if="index1 !== 0"
                        @click="deletecopymail(index,index1)"
                      ></i>
                      <span
                        style="color:#f41f1e;font-size: 14px;cursor: pointer;"
                        v-if="index1 !== 0"
                        @click="deletecopymail(index,index1)"
                      >删除</span>
                    </el-col>
                    <el-input placeholder="请输入抄送人邮箱" v-model.trim="item1.mail" style="width: 274px" disabled></el-input>
                  </el-form-item>
                </el-col>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="10" v-if="jiaofu">
                <el-form-item label="职位注意点" prop="point" class="dutyM">
                  <el-input
                    type="textarea"
                    v-model="form.point"
                    :autosize="{minRows:4}"
                    disabled
                    resize="both"
                  ></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            
            <el-row>
              <el-col :span="10">
                <el-form-item label="职位职责" prop="duty" class="dutyM">
                  <el-input
                    :disabled="input['职位职责']"
                    type="textarea"
                    v-model.trim="form.duty"
                    :autosize="{minRows:4}"
                    resize="both"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="10" :offset="2">
                <el-form-item label="任职要求" prop="require">
                  <el-input
                    type="textarea"
                    :disabled="input['任职要求']"
                    v-model.trim="form.require"
                    :autosize="{minRows:4}"
                    resize="both"
                  ></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="10">
                <el-form-item label="备注" prop="positionRemarks">
                  <el-input
                    type="textarea"
                    v-model.trim="form.positionRemarks"
                    :autosize="{ minRows: 4}"
                    disabled
                  ></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-form-item class="button">
              <el-button
                class="save"
                :disabled="once"
                @click="submitForm('form')"
              >保存
              </el-button>
              <el-button class="cancel" @click="cancelReForm">取消</el-button>
            </el-form-item>
          </el-form>
        </div>
      </el-col>
    </el-row>
  </div>
</template>
<script>
  import axios from "axios";
  import qs from "qs";
  import moment from "moment";
  import {fail} from "assert";
  import tagsView from "../../store/modules/tagsView";
  
  export default {
    name: "positionedit",
    props: {
      currentData: {
        type: Object
      }
    },
    data() {
      var salaryCap = (rule, value, callback) => {
        var salaryReg = /^\d+(-[0-9]+(\.\d{0,1})?)?$/;
        if (!value) {
          callback(new Error("请输入薪资上限"));
        } else if (value) {
          if (!salaryReg.test(value)) {
            callback(new Error("填写错误!"));
          } else {
            if (value.indexOf("-") !== -1) {
              var data = Number(value.split("-")[0]);
              var data1 = Number(value.split("-")[1]);
              if (data > data1) {
                callback(new Error("后面的数字必须大于前面的数字"));
              } else {
                callback();
              }
            } else {
              callback();
            }
          }
        }
      };
      var liaisonMail = (rule, value, callback) => {
        const mailReg = /^[A-Za-z\d]+(([-_.]*)+[A-Za-z\d]+)*@([A-Za-z\d]+[-.])+[A-Za-z\d]{2,4}$/;
        if (!value) {
          return callback(new Error("邮箱不能为空"));
        }
        setTimeout(() => {
          if (mailReg.test(value)) {
            callback();
          } else {
            callback(new Error("请输入正确的邮箱格式"));
          }
        }, 100);
      };
      var ordinaryKeywords = (rule, value, callback) => {
        function sb_strlen(str) {
          return getChars(str);
        }
        
        //得到字符总数
        function getChars(str) {
          var i = 0;
          var c = 0.0;
          var unicode = 0;
          var len = 0;
          if (str == "" || str == null) {
            return 0;
          }
          
          len = str.length;
          for (i = 0; i < len; i++) {
            unicode = str.charCodeAt(i);
            if (unicode < 127) {
              //判断是单字符还是双字符
              c += 1;
            } else {
              //chinese
              c += 2;
            }
          }
          return c;
        }
        
        function sb_substr(str, startp, endp) {
          var i = 0;
          c = 0;
          unicode = 0;
          rstr = "";
          var len = str.length;
          var sblen = sb_strlen(str);
          if (startp < 0) {
            startp = sblen + startp;
          }
          if (endp < 1) {
            endp = sblen + endp; // - ((str.charCodeAt(len-1) < 127) ? 1 : 2);
          }
          // 寻找起点
          for (i = 0; i < len; i++) {
            if (c >= startp) {
              break;
            }
            var unicode = str.charCodeAt(i);
            if (unicode < 127) {
              c += 1;
            } else {
              c += 2;
            }
          }
          // 开始取
          for (i = i; i < len; i++) {
            var unicode = str.charCodeAt(i);
            if (unicode < 127) {
              c += 1;
            } else {
              c += 2;
            }
            rstr += str.charAt(i);
            if (c >= endp) {
              break;
            }
          }
          return rstr;
        }
        
        // if (value.length < 1) {
        //   callback(new Error("请输入关键词"));
        // } else
        if (value.length > 3) {
          ("a");
          callback(new Error("关键词最多不超过三个"));
        } else if (sb_strlen(value[0]) > 12) {
          callback(new Error("关键词每一位最多不超过6个字（12个英文字母）"));
        } else if (sb_strlen(value[1]) > 12) {
          callback(new Error("关键词每一位最多不超过6个字（12个英文字母）"));
        } else if (sb_strlen(value[2]) > 12) {
          callback(new Error("关键词每一位最多不超过6个字（12个英文字母）"));
        } else {
          callback();
        }
      };
      //只存在一个抄送人邮箱的校验
      var checkEmail3 = (rule, value, callback) => {
        if (value) {
          var re = /^[A-Za-z\d]+(([-_.]*)+[A-Za-z\d]+)*@([A-Za-z\d]+[-.])+[A-Za-z\d]{2,4}$/;
          setTimeout(() => {
            if (value) {
              if (!re.test(value)) {
                callback(new Error("请输入正确的邮箱"));
              } else {
                callback();
              }
            } else {
              callback();
            }
          }, 1000);
        } else {
          callback();
        }
      };
      //不同条件下的邮箱校验
      var checkEmail1 = (rule, value, callback) => {
        if (!value) {
          return callback(new Error("邮箱不能为空"));
        }
        var re = /^[A-Za-z\d]+(([-_.]*)+[A-Za-z\d]+)*@([A-Za-z\d]+[-.])+[A-Za-z\d]{2,4}$/;
        setTimeout(() => {
          if (value) {
            if (!re.test(value)) {
              callback(new Error("请输入正确的邮箱"));
            } else {
              callback();
            }
          } else {
            callback();
          }
        }, 1000);
      };
      
      //校验座机以及手机号
      var checkphone = (rule, value, callback) => {
        if (value) {
          var re = /(^0\d{2,4}\-\d{7,8}$)|(^1[3|4|5|6|7|8|9][0-9]{9}$)/;
          
          setTimeout(() => {
            if (!re.test(value)) {
              callback(new Error("请输入正确的联系方式"));
              return false;
            } else {
              callback();
            }
          }, 1000);
        } else {
          callback();
        }
      };
      return {
        PhoneRules: [{validator: checkphone, trigger: "blur"}],
        EmailRules: [{validator: liaisonMail, trigger: "blur"}],
        EmailRules1: [{validator: checkEmail1, trigger: "blur"}],
        EmailRules3: [{validator: checkEmail3, trigger: "blur"}],
        labelPosition: "top",
        form: null,
        once: false,
        mainHr: [],
        recMails: [],
        processList: [],
        postNameList: [],
        postLevelList: [],
        jiaofuren: true,
        editBool: true,
        offs: 1,
        errorWork: false,
        customerNa: [],
        cusId: null,
        Areas: [],
        editDm: true,
        isDm: "",
        direction: "",
        charge: "",
        directions: [],
        charges: [],
        year: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
        isMul: true,
        isAdmin: false,
        jiaofu: false,
        keyBool: false,
        status: true,
        zhuli: true,
        offff: 0,
        isUnifiedInter: true, // 是否统一接口人控制输入框还是选择器
        addcopy: true, // 抄送人邮箱增加按钮点击后 变成true 验证信息是必填，只有一个抄送人邮箱时是选填
        isGangjiaosuo: false,
        star: [
          {
            label: "困难",
            num: 3
          },
          {
            label: "普通",
            num: 2
          },
          {
            label: "简单",
            num: 1
          },
          {
            label: "空",
            num: 0
          }
        ],
        rules: {
          status: [
            {required: true, message: "请选择需求状态", trigger: "change"}
          ],
          name: [{required: true, message: "请输入需求名称", trigger: "blur"}],
          techInterview: [
            {
              required: true,
              message: "请选择需不需要技术面试",
              trigger: "change"
            }
          ],
          point: [
            {required: true, message: "请输入职位注意点", trigger: "blur"}
          ],
          duty: [{required: true, message: "请输入职位职责", trigger: "blur"}],
          customerName: [
            {required: true, message: "请选择客户简称", trigger: "change"}
          ],
          introducer: [
            {required: false, message: "请输入发布人", trigger: "blur"}
          ],
          addr: [
            {required: true, message: "请选择工作地点", trigger: "change"}
          ],
          area: [
            {required: true, message: "请选择所属区域", trigger: "change"}
          ],
          postName: [
            {required: true, message: "请选择职位名称", trigger: "change"}
          ],
          // isDm: [
          //   {
          //     required: true,
          //     message: "请选择是否需要技术电面",
          //     trigger: "change"
          //   }
          // ],
          direction: [
            {required: true, message: "请选择电面方向", trigger: "change"}
          ],
          postLevel: [
            {required: true, message: "请选择职位级别", trigger: "change"}
          ],
          number: [
            {required: true, message: "请输入需求人数", trigger: "blur"},
            {
              pattern: /^[1-9]\d*$/,
              message: "需求人数为非0的正整数",
              trigger: "blur"
            }
          ],
          nextStar: [
            {required: true, message: "请选择需求程度", trigger: "change"}
          ],
          salaryCap: [{required: true, validator: salaryCap, trigger: "blur"}],
          salaryNum: [
            {required: true, message: "请输入薪数", trigger: "blur"},
            {pattern: /^\d{1,2}$/, message: "薪数为0-99的数字", trigger: "blur"}
          ],
          putTime: [
            {required: true, message: "请选择开始时间", trigger: "change"}
          ],
          endTime: [
            {required: true, message: "请选择截止时间", trigger: "change"}
          ],
          expectTime: [
            {required: true, message: "请输入期望到岗时间", trigger: "blur"}
          ],
          point: [
            {required: true, message: "请输入职位注意点", trigger: "blur"}
          ],
          duty: [{required: true, message: "请输入职位职责", trigger: "blur"}],
          require: [
            {required: true, message: "请输入任职要求", trigger: "blur"}
          ],
          interviewProcess: [
            {required: true, message: "请选择面试流程", trigger: "change"}
          ],
          nextHr: [
            {required: false, message: "请选择组别", trigger: "change"}
          ],
          entryNo: [
            {required: true, message: "请输入入职人数", trigger: "blur"}
          ],
          ordinaryKeywords: [
            {required: false, validator: ordinaryKeywords, trigger: "change"}
          ],
          mainKeywords: [
            {required: false, message: "请输入补充关键词", trigger: "change"}
          ],
          timeTable: [
            {required: true, message: "请输入作息时间", trigger: "blur"}
          ],
          workSeniority: [
            {required: true, message: "请选择工作年限", trigger: "change"}
          ]
        },
        error: false,
        error1: false,
        input: {
          需求名称: true,
          客户简称: true,
          职位名称: true,
          职位级别: true,
          需求状态: true,
          "发布人(选填)": true,
          所属区域: true,
          职位类型: true,
          需求程度: false,
          需求人数: true,
          薪资上限: true,
          薪数: true,
          工作地点: true,
          作息时间: true,
          发布时间: true,
          截止时间: true,
          期望到岗时间: true,
          技术面试: true,
          面试流程: true,
          关键词: true,
          组别: false,
          辅助招聘专员: true,
          职位注意点: true,
          职位职责: true,
          任职要求: true,
          工作年限: true
        }
      };
    },
    created() {
      //不同角色展示不同的需求状态下拉框数据
      if (tagsView.state.identity == 8) {
        // this.jiaofu = true;
        // this.jiaofuren = false;
        this.status = true;
      }
      
      if (tagsView.state.identity == 7) {
        this.jiaofu = true;
        this.jiaofuren = false;
        this.status = false;
      }
      
      axios
        .post(this.url + "/auth/getSectionByModular", {
          modularId: 39
        })
        .then(res => {
          this.unlogin(res.data.code);
          if (res.data.code == 200) {
            for (let i = 0, leng = res.data.data.length; i < leng; i++) {
              if (res.data.data[i].sectionId == "100223") {
                this.isAdmin = true;
                this.offs = 1;
              }
              if (res.data.data[i].sectionId == "100220") {
                this.keyBool = true;
                this.offff = 1;
              }
            }
          }
        });
      //获取组别下拉框的数据
      axios
        .post(this.url + "/demand/getMemberss", {
          hrName: []
        })
        .then(res => {
          this.unlogin(res.data.code);
          if (res.data.code == 200) {
            this.mainHr = res.data.data;
          }
        });
      //判断能否修改组别和需求程度
      axios
        .post(this.url + "/demand/isWrite", {
          id: this.currentData.id
        })
        .then(res => {
          this.unlogin(res.data.code)
          if (res.data.code == 200) {
            this.input["组别"] = res.data.data;
            this.input["需求程度"] = res.data.data;
          }
        });
      
      axios.post(this.url + '/demand/isDemandClose').then(res => {
        this.unlogin(res.data.code);
        if (res.data.code == 200) {
          this.input["需求状态"] = res.data.data;
        }
      })
      
      
      axios
        .get(this.url + "/demand/getAreas") // 地区下拉列表请求
        .then(res => {
          this.unlogin(res.data.code);
          if (res.data.code == 200) {
            this.Areas = res.data.data;
          }
        });
      axios
        .get(this.url + "/demand/getDirection") // 技术方向下拉列表请求
        .then(res => {
          this.unlogin(res.data.code);
          if (res.data.code == 200) {
            this.directions = res.data.data;
          }
        });
      axios.get(this.url + "/process/getstring").then(res => {
        this.unlogin(res.data.code);
        if (res.data.code == 200) {
          let arr = JSON.parse(JSON.stringify(res.data.data));
          arr.sort(
            (a, b) => a.interviewProcess.length - b.interviewProcess.length
          );
          this.processList = arr;
        }
      });
    },
    mounted() {
      axios
        .get(this.url + "/demand/getCustomerNames") // 客户名称下拉列表请求
        .then(res => {
          this.unlogin(res.data.code);
          if (res.data.code == 200) {
            this.customerNa = res.data.data;
          }
        });
      axios
        .post(
          this.url + "/demand/getJobDetail",
          qs.stringify({
            //职位需求明细请求
            id: this.currentData.id
          })
        )
        .then(res => {
          this.unlogin(res.data.code);
          if (res.data.code == 200) {
            var resdata = res.data.data;
            
            resdata.nextHr = resdata.nextHr.split(",");
            
            if (resdata.nextHr[0] == "," || resdata.nextHr[0] == "") {
              resdata.nextHr.shift();
            }
            
            delete resdata.createTime;
            if (resdata.customerName == "港交所") {
              this.isGangjiaosuo = true;
            } else {
              this.isGangjiaosuo = false;
            }
            if (resdata.ordinaryKeywords) {
              resdata.ordinaryKeywords = resdata.ordinaryKeywords.split(",");
            } else {
              resdata.ordinaryKeywords = [];
            }
            if (resdata.mainKeywords) {
              resdata.mainKeywords = resdata.mainKeywords.split(",");
            } else {
              resdata.mainKeywords = [];
            }
            resdata.area = resdata.area.split(",");
            resdata.postLevel = resdata.postLevel.split(",");
            (resdata.putTime = moment(resdata.putTime).format("YYYY-MM-DD")),
              (resdata.endTime = moment(resdata.endTime).format("YYYY-MM-DD")),
              (this.form = resdata);
            for (let i = 0, len = this.customerNa.length; i < len; i++) {
              if (this.customerNa[i].name == resdata.customerName) {
                this.cusId = this.customerNa[i].id;
              }
            }
            // 职位名称下拉框请求
            axios
              .post(this.url + "/demand/getPostNameByCustomerId", {
                customerId: this.cusId + ""
              })
              .then(res => {
                this.unlogin(res.data.code);
                if (res.data.code == 200) {
                  this.postNameList = res.data.data;
                }
              });
            // 职位级别下拉框请求
            axios
              .post(this.url + "/demand/getPostLevelByNameAndCustomerId", {
                postName: this.form.postName + "",
                customerId: this.cusId + ""
              })
              .then(res => {
                this.unlogin(res.data.code);
                if (res.data.code == 200) {
                  this.postLevelList = res.data.data;
                }
              });
            //收件人邮箱下拉框请求
            axios
              .post(this.url + "/demand/getRecMails", {
                customerId: this.cusId + ""
              })
              .then(res => {
                this.unlogin(res.data.code);
                if (res.data.code == 200) {
                  this.recMails = res.data.data;
                }
              });
            resdata.dutyArr = resdata.duty.split(/\n/);
            resdata.requireArr = resdata.require.split(/\n/);
          }
        });
    },
    methods: {
      isDmclear() {
        this.form.direction = "";
        this.form.charge = "";
      },
      customerNameChange(val) {
        for (let i = 0, len = this.customerNa.length; i < len; i++) {
          if (this.customerNa[i].name == val) {
            this.cusId = this.customerNa[i].id;
          }
        }
        this.form.postName = "";
        this.form.postLevel = [];
        // 职位名称下拉框请求
        axios
          .post(this.url + "/demand/getPostNameByCustomerId", {
            customerId: this.cusId + ""
          })
          .then(res => {
            this.unlogin(res.data.code);
            if (res.data.code == 200) {
              this.postNameList = res.data.data;
            }
          });
        // 是否统一接口人请求
        axios
          .post(this.url + "/demand/getIsUnifiedInter", {
            customerName: this.form.customerName
          })
          .then(res => {
            this.unlogin(res.data.code);
            if (res.data.code == 200 && res.data.data == "Y") {
              this.isUnifiedInter = true;
              axios
                .post(
                  this.url + "/demand/getLiaisonByCustomerId",
                  qs.stringify({
                    customerId: this.cusId + ""
                  })
                )
                .then(res => {
                  this.unlogin(res.data.code);
                  if (res.data.code == 200) {
                    if (res.data.data.length < 2) {
                      this.form.liaisonList = res.data.data;
                    } else {
                    }
                  }
                });
              //收件人邮箱下拉框请求
              axios
                .post(this.url + "/demand/getRecMails", {
                  customerId: this.cusId + ""
                })
                .then(res => {
                  this.unlogin(res.data.code);
                  if (res.data.code == 200) {
                    this.recMails = res.data.data;
                  }
                });
            } else {
              this.isUnifiedInter = false;
              this.form.liaisonList = [
                {
                  receiverMail: "",
                  cpSendMails: [
                    {
                      mail: ""
                    }
                  ]
                }
              ];
            }
          });
      },
      //收件人邮箱改变
      recMailChange(val) {
        let reId = 0;
        for (let i = 0, len = this.recMails.length; i < len; i++) {
          if (this.recMails[i].mail == val) {
            reId = this.recMails[i].id;
          }
        }
        axios
          .post(this.url + "/demand/getCpMailsByRecId", {
            recId: reId + ""
          })
          .then(res => {
            this.unlogin(res.data.code);
            if (res.data.code == 200) {
              this.form.liaisonList[0].cpSendMails = [];
              for (let i = 0, len = res.data.data.length; i < len; i++) {
                this.form.liaisonList[0].cpSendMails.push({
                  mail: res.data.data[i] + ""
                });
              }
              this.$forceUpdate();
            }
          });
      },
      directionChange(val) {
        this.form.charge = '';
        // 面试人员下拉框请求
        axios
          .post(this.url + "/demand/getPeopleByGroup", {
            direction: val + ""
          })
          .then(res => {
            this.unlogin(res.data.code);
            if (res.data.code == 200) {
              this.charges = res.data.data;
              this.form.charge = this.charges[0];
            }
          });
      },
      postNameChange(val) {
        this.form.postLevel = [];
        // 职位级别下拉框请求
        axios
          .post(this.url + "/demand/getPostLevelByNameAndCustomerId", {
            postName: val + "",
            customerId: this.cusId + ""
          })
          .then(res => {
            this.unlogin(res.data.code);
            if (res.data.code == 200) {
              this.postLevelList = res.data.data;
            }
          });
      },
      //添加抄送人邮箱
      addcopymail(index) {
        // if (this.form.liaisonList[index].cpSendMails.length < 6) {
        //   this.form.liaisonList[index].cpSendMails.push({mail: ""});
        //   this.$forceUpdate();
        // } else {
        //   return false;
        // }
      },
      //删除抄送人邮箱
      deletecopymail(index, index1) {
        // this.form.liaisonList[index].cpSendMails.splice(index1, 1);
        // this.$forceUpdate();
      },
      submitForm(formName) {
        if (!this.error && !this.error1) {
          this.$refs[formName].validate(valid => {
            if (valid) {
              axios.post(this.url + "/demand/updateNextJob", {
                Id: this.currentData.id,
                nextHr: this.form.nextHr,
                nextStar: this.form.nextStar,
                status: this.form.status
              }).then(res => {
                this.unlogin(res.data.code);
                if (res.data.code == 200 && res.data.message == "success") {
                  this.$emit("sendSuccess");
                  this.once = false;
                }
              });
            } else {
              console.log("error submit!!");
              return false;
            }
          });
        }
      },
      cancelReForm() {
        this.$emit("Rehide");
      }
    },
    watch: {
      "form.putTime": function (val) {
        if (this.form.endTime == "") {
          return false;
        } else if (val > this.form.endTime) {
          this.error = true;
        } else {
          this.error = false;
          this.error1 = false;
        }
      },
      "form.endTime": function (val) {
        if (this.form.endTime == "") {
          return false;
        } else if (val < this.form.putTime) {
          this.error1 = true;
        } else {
          this.error1 = false;
          this.error = false;
        }
      },
      "form.entryNo": function (val) {
        if (val > this.form.number) {
          this.errorWork = true;
        } else {
          this.errorWork = false;
        }
      }
    }
  };
</script>
<style scoped>
  /* .Line {
      border: 0.5px solid #e8e8e8;
      margin-top: 6px;
      margin-bottom: 20px;
    } */
  .save {
    width: 150px;
    height: 40px;
    font-size: 16px;
    color: #fff;
    border-radius: 4px;
    margin-right: 43px;
    background: linear-gradient(to bottom, #5696f8 0%, #4e6ef5 100%);
  }
  
  .cancel {
    width: 150px;
    height: 40px;
    border: 1px solid #4e6ef5;
    font-size: 16px;
    font-weight: 500;
    color: #4e6ef5;
  }
  
  .workMember {
    height: 33px;
    border: 1px solid #c8ccd5;
    min-width: 274px;
  }
  
  .posttable i,
  span {
    cursor: pointer;
    font-weight: 700;
  }
  
  .posttable i {
    cursor: pointer;
  }
</style>
